package org.alexisjago.footballmanager.DAO;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.alexisjago.footballmanager.domain.Match;

public class MatchDAO implements IMatchDAO {
	
	/* (non-Javadoc)
	 * @see org.alexisjago.footballmanager.DAO.IMatchDAO#saveMatch(org.alexisjago.footballmanager.domain.Match)
	 */
	@Override
	public void saveMatch(Match match) {
		PersistenceManager.entityManager.persist(match);
	}
	
	/* (non-Javadoc)
	 * @see org.alexisjago.footballmanager.DAO.IMatchDAO#loadMatch(int)
	 */
	@Override
	public Match loadMatch(int id){
		
		Match match = PersistenceManager.entityManager.find(Match.class, id);

		return match;
	}

	/* (non-Javadoc)
	 * @see org.alexisjago.footballmanager.DAO.IMatchDAO#getMatches()
	 */
	@Override
	public List<Match> getMatches(){
		@SuppressWarnings("unchecked")
		List<Match> matches = (List<Match>)PersistenceManager.entityManager.createQuery("from Match").getResultList();
		return matches;
	}
}
